package com.ltu.controller.customize;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import com.ltu.enums.MqTopiceDict;
import com.ltu.model.response.base.CodeDataResp;
import com.ltu.service.customize.SessionInfoService;
import com.ltu.service.mqtt.MqttPushClient;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;

@Api(tags = "MqttController", description = "MQTT测试接口")
	@RestController
	@RequestMapping("/mqtt")
	public class MqttController {
		@Autowired
		private MqttPushClient   mqttPushClient;
		@Autowired
		private  SessionInfoService sessionInfoService;
		
		
		@PostMapping("/sendToDlayedTopic")
		@ApiOperation("发送延迟消息")
		public CodeDataResp sendToDlayedTopic(String payload, String topic,String second) {
			Object[] param = new Object[2];
			param[0]=second;
			param[1]=MqTopiceDict.OrderEnum.OrderPayListen.getValue();
			String fullTopic =	String.format(MqTopiceDict.DelayedPrefix, param);
			mqttPushClient.pushlish(fullTopic,payload);
			return CodeDataResp.valueOfSuccessEmptyData();
		}

		@PostMapping("/sendToTopic")
		@ApiOperation("向指定主题发送消息")
		public CodeDataResp sendToTopic(String payload, String topic) {
			mqttPushClient.pushlish(topic,payload);
			
			return CodeDataResp.valueOfSuccessEmptyData();
		}
		
	
		
		@PostMapping("/subscribeTopic")
		@ApiOperation("订阅某个主题")
		public CodeDataResp subscribe( String topic) {
			mqttPushClient.subscribe(topic, 0);
			return CodeDataResp.valueOfSuccessEmptyData();
		}
		
		
		@PostMapping("/getCurSessionQRCode")
		@ApiOperation("测试生成微信二维码文件")
		public CodeDataResp getCurSessionQRCode( String id) {
			sessionInfoService.getCurSessionQRCode( sessionInfoService.getById(id));
			return CodeDataResp.valueOfSuccessEmptyData();
		}
		
		
		
	}


